<?php
// +-----------------------+
// | 注释不留名，代码随便用 |
// +-----------------------+

namespace app\common\library\auth;
class WechatMini
{
    public static $login_key = 'erp_member_login_';
    public static $member_key = 'member_info';

    public static function login($data,$callback = null)
    {
        $cache = cache(self::$login_key . $mobile);

        if($callback instanceof \Closure){
            call_user_func($member);
        }
        //记录登录信息
        $info = $member->toArray();
        foreach(['password','salt'] as $field){
            unset($info[$field]);
        }
        self::setMemberInfo($info);
        return true;
    }

    public function isLogin(){
        return !empty(self::getMemberInfo());
    }

    public static function setMemberInfo($info){
        session(self::$member_key, $info);
    }

    public static function getMemberInfo(){
        return session(self::$member_key);
    }

    public static function getSessionKey(){
        return session_id();
    }
    public static function setSessionKey($key){
        if($key){
            session_id($key);
            Session::boot();
        }
    }
    /**
     * 自动登录
     * @param $key
     * @return bool
     */
    public static function autoLogin(){

        return !empty(self::getMemberInfo());
    }

}
